local sk__wurong = fk.CreateSkill {

  name = "sk__wurong",

  tags = {},

}



sk__wurong:addEffect("active", {
  name = "sk__wurong",
  anim_type = "control",
  card_num = 0,
  target_num = 1,
  prompt = "#sk__wurong",
  can_use = function(self, player)
    return player:usedSkillTimes(sk__wurong.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, player, to_select, selected, selected_cards)
    return #selected == 0 and to_select ~= player and not to_select:isKongcheng()
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    local card = room:askForCardChosen(player, target, "h", sk__wurong.name, "#sk__wurong-choose::" .. target.id)
    local type = Fk:getCardById(card):getTypeString()
    target:showCards(card)
    if player.dead or player:isKongcheng() then return end
    local card2 = room:askForDiscard(player, 1, 1, false, sk__wurong.name, true, ".",
      "#sk__wurong-discard::" .. target.id .. ":" .. type, true)
    if #card2 == 0 then return end
    room:throwCard(card2, sk__wurong.name, player, player)
    if Fk:getCardById(card2[1]):getTypeString() == type then
      if player.dead then return end
      if table.contains(target:getCardIds("h"), card) then
        room:moveCardTo(card, Card.PlayerHand, player, fk.ReasonPrey, sk__wurong.name, nil, true, player.id)
      end
      if not player.dead and not target.dead and not target:isKongcheng() and
          room:askForSkillInvoke(player, sk__wurong.name, nil, "#sk__wurong-invoke::" .. target.id) then
        player:broadcastSkillInvoke(sk__wurong.name)
        room:notifySkillInvoked(player, sk__wurong.name)
        room:doIndicate(player.id, { target.id })
        local sk__wurong_skill=Fk.skills[sk__wurong.name]
        sk__wurong_skill:onUse(room, {
          from = player,
          tos = { target },
        })
      end
    elseif not target.dead then
      if not player.dead then
        local skills = {}
        for _, s in ipairs(target.player_skills) do
          if s:isPlayerSkill(target) and not s:hasTag(Skill.Compulsory,true)then
            table.insertIfNeed(skills, s.name)
          end
        end
        if #skills > 0 then
          local choice = room:askForChoice(player, skills, sk__wurong.name, "#sk__wurong-choice::" .. target.id)
          local mark = target:getTableMark("@sk__wurong-turn")
          table.insertIfNeed(mark, choice)
          room:setPlayerMark(target, "@sk__wurong-turn", mark)
        end
      end
      room:damage({
        from = player,
        to = target,
        damage = 1,
        skillName = sk__wurong.name,
      })
    end
  end,
})

sk__wurong:addEffect("invalidity", {
  name = "#sk__wurong_invalidity",
  invalidity_func = function(self, from, skill)
    return skill:isPlayerSkill(from) and table.contains(from:getTableMark("@sk__wurong-turn"), skill.name)
  end
})

return sk__wurong
